﻿Public Class Form1

    Private _party As PartyObj

    Public Sub New()

        InitializeComponent()
        AppConstants.SetUpComboBox(cboHero1Class, BuildHeroClassDataTable())
        AppConstants.SetUpComboBox(cboHero2Class, BuildHeroClassDataTable())
        AppConstants.SetUpComboBox(cboHero3Class, BuildHeroClassDataTable())
        AppConstants.SetUpComboBox(cboHero4Class, BuildHeroClassDataTable())
        
    End Sub

    Private Function BuildHeroClassDataTable() As DataTable

        Dim dt As New DataTable()
        dt.Columns.Add(AppConstants.ValueColumnName)
        dt.Columns.Add(AppConstants.DisplayColumnName)

        dt.Rows.Add(New Object() {eHeroClass.None, "(None)"})

        For i As Integer = 1 To [Enum].GetNames(GetType(eHeroClass)).Length - 1
            dt.Rows.Add(New Object() {i, AppConstants.TranslateHeroClassName(i)})
        Next

        Return dt

    End Function

    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click

        _party = New PartyObj()

        If cboHero1Class.SelectedIndex <> eHeroClass.None Then

            AddHeroControls(pnlHero1, cboHero1Class)

        End If

        If cboHero2Class.SelectedIndex <> eHeroClass.None Then

            AddHeroControls(pnlHero2, cboHero2Class)

        End If

        If cboHero3Class.SelectedIndex <> eHeroClass.None Then

            AddHeroControls(pnlHero3, cboHero3Class)

        End If

        If cboHero4Class.SelectedIndex <> eHeroClass.None Then

            AddHeroControls(pnlHero4, cboHero4Class)

        End If

        btnStart.Visible = True

    End Sub

    Private Sub AddHeroControls(ByVal pnl As Panel, ByVal cbo As ComboBox)

        pnl.Controls.Clear()
        Dim hero As HeroObj = GenerateHero(CShort(cbo.SelectedValue))
        pnl.Controls.Add(New BasicStatPanel(hero))
        _party.Heroes.Add(hero)

    End Sub

    Private Function GenerateHero(ByVal heroClassId As Short) As HeroObj

        Dim hero As HeroObj = Nothing

        Select Case heroClassId

            Case eHeroClass.Barbarian
                hero = New BarbarianObj()

            Case eHeroClass.DwarvenWarrior
                hero = New DwarvenWarriorObj

            Case eHeroClass.ElvenWarrior
                hero = New ElvenWarriorObj

            Case eHeroClass.Wizard
                hero = New WizardObj

        End Select

        Return hero

    End Function

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

        Dim f As New Dungeon(_party)
        f.Show()
        Me.Hide()

    End Sub

    Private Sub mnuMonsterDataDesigner_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMonsterDataDesigner.Click
        Dim f As New MonsterDataDesigner
        f.Show()
    End Sub

    Private Sub CurrentDirectoryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrentDirectoryToolStripMenuItem.Click
        MessageBox.Show(IO.Directory.GetCurrentDirectory())
    End Sub

    Private Sub mnuHeroDataDesigner_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHeroDataDesigner.Click
        Dim f As New HeroDataDesigner
        f.Show()
    End Sub
End Class